package com.teradata

import org.json4s.{DefaultFormats, Formats}
import org.scalatra.ScalatraServlet
import org.scalatra.json.JacksonJsonSupport
import org.slf4j.LoggerFactory

class iopParseScalatra extends ScalatraServlet with JacksonJsonSupport {
  private val LOGGER=LoggerFactory.getLogger(this.getClass)

  protected implicit val jsonFormats: Formats = DefaultFormats

  before() {
    contentType = formats("json")
  }

  get("/iopParse/:actId") {
    <h1>ok</h1>
    val body = params("actId").toString
    println(body)
    //    IopRuleParserMain2.iopParse(Array(body))
  }

  post("/iopParse/:actId") {


    val svcType = params("actId").toString

    if (svcType.matches("(?m)[0-9A-Z]{4,8}")) {
      val parseThread = new Thread(new Runnable {
        override def run(): Unit = IopRuleParserMain.iopParse(svcType)
      })
      parseThread.start()
      "SvcType " + svcType + " started!\n"
    } else {
      "Wrong SvcType!\n"
    }

  }

  notFound {
    contentType = "text/html"
    serveStaticResource() getOrElse resourceNotFound()
  }


}


